{include file="common/head"}
<head>
<title>权限组管理</title>

<style>
    a{text-decoration:none;}
    .view{
        display: inline-block;
    }
    .edit{display: none;}
</style>
</head>
<body >
<div class="container-fluid">
    <div><h2>权限组管理</h2></div>
    <table class="table table-sm table-hover table-striped table-bordered">
        <thead class="table-info">
            <th>序号</th>
            <th>群组名</th>
            <th>状态</th>
            <th>创建时间</th>              
            <th>创建人</th>        
            
            <th>
                <button type="button" class="btn btn-sm btn-primary" id="add_group">
                    <span class="bi-plus-lg" style="color:white;"></span>
                </button>
            </th>
        </thead>
        <tbody>
            {foreach $list as $k=>$kv}
            <tr id="{$kv['id']}">
                <td>{$k+1}</td>
                <td>
                <name class='view'>{$kv['name']}</name>
                <e class='edit'>
                    <input type="text" value="{$kv['name']}"  class="form-control"/>
                </e>
                </td>
                <td>
                <status class="view" status="{$kv['status']}" {if $kv['status']==2} style="color:red;"{/if}>
                {$kv['status_name']}
                </status>
                <e class="edit">
                    <select name="status" class="form-control" >
                        <option value="1" {if $kv['status']==1} selected {/if}>正常</option>
                        <option value="2" {if $kv['status']==2} selected {/if}>停用</option>
                    </select>
                </e>
            </td>
                <td>{$kv['create_time']}</td>
                <td>{$kv['creater_name']}</td>
                
                <td>
                    <button type="button" class="btn btn-sm btn-info btn_view view"><span class="bi-pencil"></span> </button>
                    <button type="button" class="btn btn-sm btn-info btn_save edit"><span class="bi-check"></span> </button>
                    <button type="button" class="btn btn-sm btn-info btn_x edit"><span class="bi-x"></span> </button>
                </td>
            </tr>
            {/foreach}

        </tbody>    
    </table>
</div>

</body>

<script type="text/javascript">
$(document).ready(function(){
    $("#add_group").on('click',function(e){
      layer.prompt({title: '输入新组名', formType: 3}, function(text, index){
        //layer.msg('您最后写下了：'+text);
        layer.close(index);
        $.post('group_edit',{'name':text},function(res){
            layer.msg(res.msg);
            location.reload();
        })
      });


    })

    $(".btn_view").on('click',function(){
        $(this).parents('tr').find('.view').hide();
        $(this).parents('tr').find('.edit').show();
    })
    $(".btn_x").on('click',function(){
        $(this).parents('tr').find('.view').show();
        $(this).parents('tr').find('.edit').hide();
    })    

    $(".btn_save").on('click',function(){
        var tr =$(this).parents('tr');

        var o_name = tr.find('name').text();
        var o_status = tr.find('status').attr('status');

        var name = tr.find("input[type='text']").val();
        var status =tr.find("select").val();

        if(name == o_name && status==o_status){
            layer.msg('你这不是啥也没动吗？');
            return;
        }

        var id = tr.attr('id');

        layer.confirm('是否确定保存?',
            {btn:['Ok','No']},
            function(){
                $.post('group_edit',{name:name,id:id,status:status},function(res){
                    if(res.code){
                        location.reload();
                    }
                    layer.msg(res.msg);
                    
                })
            },function(){

        })
    });

})

</script>


</body>
</html>
